package com.qf.emp.controller;

import com.qf.emp.entity.Emp;
import com.qf.emp.entity.Page;
import com.qf.emp.service.EmpService;
import com.qf.emp.service.impl.EmpServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet(name = "showAllEmpController",value = "/manager/safe/showAllEmpController")
public class showAllEmpController extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        System.out.println("登录成功！查询所有！");
        String pageIndex = request.getParameter("pageIndex");
        if (pageIndex == null){
            pageIndex = "1";
        }

        Page page = new Page(Integer.valueOf(pageIndex));
        EmpService empService = new EmpServiceImpl();
        List<Emp> emps = empService.showAllEmp();
        request.setAttribute("emps", emps);
        request.setAttribute("page",page);
        request.getRequestDispatcher(request.getContextPath()+"/showAllEmp.jsp").forward(request, response);
    }
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
            doPost(request, response);
    }
}
